<?php
class MySQL{
    private $servidor				='localhost';       	       
    private $base_de_dades			='cartas';		    	  
    private $usuari					='root';	            
    private $contrasenya            ='';					
	
    /*
    private $servidor				='10.1.0.20';       	       
    private $base_de_dades			='cartas';		    	  
    private $usuari					='gCartas';	            
    private $contrasenya            ='c4rt4s';	
	
    */
    
    private $connect;                                  
    private $error;                    

   function Conectar(){
        $this -> connect = @mysql_connect( $this -> servidor, $this -> usuari, $this -> contrasenya );         

        if( !$this -> connect ){
            $this -> error = mysql_error();
            return( False );
        }else{
            if( strlen($this -> base_de_dades) > 0 ){$this -> SeleccionarBaseDatos();}
            return( $this -> connect );
        }
    }
     
    function SeleccionarBaseDatos( $bd = "", $con = null ){
        if( strlen($bd) > 0 ){$this -> base_de_dades = $bd;}
        if( isset($con) ){$this -> connect = $con;}
         
        if( !mysql_select_db($this -> base_de_dades, $this -> connect) ){
            $this -> error = mysql_error();
            return( False );
        }else{
           return( True );
        }
    }
  
    function UltimoID(){
        return( mysql_insert_id() );
    }
 
    function VerError()
    {
        if( $this->error != Null ){
            return( $this->error );
        }
        else{
            return( False );
        }
    }
     
    function limpiar($variable){
        if( get_magic_quotes_gpc() ){$variable = mysql_real_escape_string(stripslashes(trim($variable)));}
        else{$variable =mysql_real_escape_string(trim($variable));}
        return( $variable );
    }
         
    function CerrarConexion()
    {
        if(!@mysql_close($this->connect)){
            $this->error = mysql_error();
            return( False );
        }else{
            return( True );
        }
    }
 
    function LimpiarConsulta(){
        if(!@mysql_free_result($this->sql))
        {  
            $this->error = mysql_error();
            return( False );
        }else{
            return( True );
        }
    }	
}
?>